package com.study.demo_resttemplate.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

/**
 * @Name: RestConfig
 * @Description: java类作用描述
 * @Author: yn
 * @CreateDate: 2022/7/15 11:42
 * @Remark: 特殊说明
 * @Version: 1.0
 */
@Configuration
public class RestConfig {

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    @Bean
    public UserAgentInterceptor userAgentInterceptor(){
        return new UserAgentInterceptor();
    }

    @Bean
    public RestTemplate restTemplateWithInterceptors(UserAgentInterceptor userAgentInterceptor){
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setInterceptors(Collections.singletonList(userAgentInterceptor));
        return restTemplate;
    }
}
